//
//  Experiment.cpp
//  GPUProcessingTesting
//
//  Created by kadlubek47 on 20.08.2013.
//  Copyright (c) 2013 kadlubek47. All rights reserved.
//

#include "Experiment.h"



const std::string Experiment::afterMainDescription_      = std::string ("-------------------------------------\n\n\n\n");
const std::string Experiment::afterTrialsSetDescription_ = std::string ("***\nTrials:\n");
const std::string Experiment::afterTrialsSet_            = std::string ("***\n\n\n");



#pragma mark Construct, destroy

Experiment::Experiment(const std::string& mainDescription, const std::string& fileName, const std::string& folderPath): mainDescription_(mainDescription), fileName_(fileName), folderPath_(folderPath) {}

Experiment::~Experiment() {}

void Experiment::add_trialsSet (TrialsSet trialsSet) {
    trialsSets_.push_back(trialsSet);
}



#pragma mark Writing to file

void Experiment::writeTo_file   (bool ifEachTrialPrinted) {
    using namespace std;
    
    //Creating file for writing
    string filePath;
    filePath.append(folderPath_);
    filePath.append(fileName_);
    ofstream fs(filePath.c_str(), ios_base::out | ios_base::trunc);
    //.
    writeToStream(fs);
    fs.close();
}

void Experiment::writeTo_stdcout(bool ifEachTrialPrinted) {
    writeToStream(std::cout, false);
}

//HERE CORE WRITING
void Experiment::writeToStream(std::ostream& outputStream, bool ifEachTrialPrinted) {
    //Writing to file
    outputStream << mainDescription_;
    outputStream << afterMainDescription_;
    
    unsigned long numberOfTrialsSet = trialsSets_.size();
    
    for(int i = 0; i < numberOfTrialsSet; ++i) {    //for each
        //outputStream << trialsSets_[i].description_;
        if(ifEachTrialPrinted) {
            outputStream << afterTrialsSetDescription_;
            for(int j = 0; j < trialsSets_[i].get_trialsNumber(); ++j) {
                outputStream << trialsSets_[i].get_trial(j) << std::endl;
            }
        }
        outputStream << afterTrialsSet_;
    }
    outputStream << std::endl;
    //.
}